package destination8089.controller;


import destination8089.entity.param.DestinationAddParam;
import destination8089.entity.po.Destination;
import destination8089.entity.vo.ResultVO;
import destination8089.service.DestinationService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ttxxi
 * @since 2022-05-31
 */
@RestController
@RequestMapping("/destination")
public class DestinationController {
    @Resource
    DestinationService destinationService;

    @GetMapping
    @ApiOperation(value = "查询所有终点站")
    public ResultVO<List<Destination>> getAll(){
        List<Destination> list = destinationService.list();
        return new ResultVO.SUCCESS<>(list);
    }

    @PostMapping
    @ApiOperation(value = "增加终点站")
    public ResultVO addDestination(@RequestBody DestinationAddParam param){
        Boolean res = destinationService.addDestination(param);
        if (res){
            return new ResultVO.SUCCESS<>();
        }else {
            return new ResultVO.FAIL<>();
        }
    }

    @DeleteMapping
    @ApiOperation(value = "删除终点站")
    public ResultVO deleteDestination(Long id){
        boolean res = destinationService.removeById(id);
        if (res){
            return new ResultVO.SUCCESS<>();
        }else {
            return new ResultVO.FAIL<>();
        }
    }
}

